/**
    @file       2007_V6_D.c
    @date       2013-09-29 13:42
    @author     Yura Gorishniy
    @version    1.02

    @par        The program asks for a natural number and
                returns the amount of different decompositions in natural summands.
                For example, if user's number is 5, the program will return 7
                (5 = 5 = 4 + 1 = 3 + 2 = 3 + 1 + 1 =
                 = 2 + 2 + 1 = 2 + 1 + 1 + 1 = 1 + 1 + 1 + 1 + 1

    @note       V.1.01
                - added the description of function "main"
                - added the description of the program
                - some minor fixes

                V.1.02
                - code style improved
                - names of some variables were changed
                - deleted unnecessary variable i
                - now main function prints information about the program

**/

#include <stdio.h>
#include <stdlib.h>


//#define DEBUG

#ifdef DEBUG
    #define ASSERT(cond)                                                                        \
    if (!(cond))                                                                                \
    {                                                                                           \
        printf("The state is wrong: %s, file: %s, line: %d\n", #cond, __FILE__, __LINE__);      \
        abort();                                                                                \
    }
#else
    #define ASSERT(cond)
#endif //DEBUG


//#define _EJC

#ifdef  _EJC
    #define OUT if (0)
#else
    #define OUT
#endif // _EJC

/**
    Decomps_Amount - finds the amount of different decompositions of the number in natural summands

    @param      num         The number, which the function will decompose
    @param      nSummands   The number shows the biggest possible amount of
                            summands in one decomposition

    @return                 The amount of different decomposions

    @note                   The number and summands are natural
**/

long Decomps_Amount (int num, int nSummands);


/**
    main        asks for a natural number, which a user wants to decompose
                prints the number of possible decomposition in natural summands

    @return     0 if the program finishes successfully
               -1 if input is incorrect

**/

int main ()
{
    int n = 0;
    long nDecomps = 0;

    OUT printf ("# This program finds the amount of different decompositions\n"
                "  of a natural number in natural summands\n"
                "  (the amount of them is equal to the number or less)\n"
                "# The developer:   Yura Gorishniy      <strausmg@gmail.com>\n"
                "# Version 1.02\n"
                "# The file: %s\n"
                "# The compilation time: %s, %s\n\n", strrchr (__FILE__, '\\'), __DATE__, __TIME__);

    OUT printf ("# Enter a natural number you want to decompose (type it and press ENTER)\n\n");

    if (scanf ("%d", &n) != 1) {printf ("Incorrect input, try again"); return -1;}

    nDecomps = Decomps_Amount (n, n);

    OUT printf ("\n" "# The amount of possible decompositions:\n");
    printf ("%ld", nDecomps);

return 0;
}

long Decomps_Amount (int num, int nSummands)
{
    if (nSummands == 0 || num < 0)
    {
            return 0;
    }

    else
    {
        if (nSummands == 1) return 1;
        else return Decomps_Amount (num - nSummands, nSummands) + Decomps_Amount (num, nSummands - 1);
    }
}
